﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RoyTools.D3Monitor.FormUI.Helper;
using System.Windows.Forms;

namespace RoyTools.D3Monitor.FormUI
{
    /// <summary>
    /// 监视器管理器
    /// </summary>
    public class MonitorManager
    {
        /// <summary>
        /// 停止日志监视器
        /// </summary>
        public static void StopLogMonitor()
        {
            if (Program.LogWatcherList != null)
            {
                Program.LogWatcherList.ForEach(l => {
                    l.Stop();
                });
                Program.LogWatcherList = null;
            }
        }

        /// <summary>
        /// 设置日志监视器
        /// </summary>
        public static void SetLogMonitor()
        {
            if (Program.LogWatcherList == null)
            {
                Program.LogWatcherList = new List<LogWatcher>();
            }

            if (Program.Config.LogMonitorSettings != null)
            {
                Program.Default.lsvLog.Items.Clear();
                Program.Config.LogMonitorSettings.ForEach(l =>
                {
                    Program.Default.lsvLog.Items.Add(new ListViewItem(l.Name));

                    var logWatcher = new LogWatcher();
                    logWatcher.SetMonitorDirectory(l);
                    Program.LogWatcherList.Add(logWatcher);
                });
            }
        }
    }
}
